/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SWANLINK_FINANCE_KEYBOARD_UTILS_NATIVE_INCLUDE_HILOG_WRAPPER_H
#define SWANLINK_FINANCE_KEYBOARD_UTILS_NATIVE_INCLUDE_HILOG_WRAPPER_H

#define CONFIG_HILOG
#ifdef CONFIG_HILOG
#include "hilog/log.h"
namespace SwanLink {
namespace  Finance{
using namespace OHOS;
#define __FILENAME__            (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
#define __FORMATED(fmt, ...)    "[%{public}s] %{public}s# " fmt, __FILENAME__, __FUNCTION__, ##__VA_ARGS__

#ifdef KEYBOARD_HILOGF
#undef KEYBOARD_HILOGF
#endif

#ifdef KEYBOARD_HILOGE
#undef KEYBOARD_HILOGE
#endif

#ifdef KEYBOARD_HILOGW
#undef KEYBOARD_HILOGW
#endif

#ifdef KEYBOARD_HILOGI
#undef KEYBOARD_HILOGI
#endif

#ifdef KEYBOARD_HILOGD
#undef KEYBOARD_HILOGD
#endif

enum KEYBOARD_MODULE {
    KEYBOARD_UTIL = 0,
    KEYBOARD_KITS,
    KEYBOARD_INNERKITS,
    KEYBOARD_JS_NAPI,
    KEYBOARD_SRV,
    KEYBOARD_ADAPTOR,
    KEYBOARD_TEST,
    KEYBOARD_BUTT
};
// In order to improve performance, do not check the module range.

static constexpr OHOS::HiviewDFX::HiLogLabel KEYBOARD_LABEL[KEYBOARD_BUTT] = {
    {LOG_CORE, KEYBOARD_UTIL,            "KeyboardUtils"},
    {LOG_CORE, KEYBOARD_KITS,            "KeyboardKits"},
    {LOG_CORE, KEYBOARD_INNERKITS,       "KeyboardInnerKits"},
    {LOG_CORE, KEYBOARD_JS_NAPI,         "KeyboardJsNapi"},
    {LOG_CORE, KEYBOARD_SRV,             "KeyboardSrv"},
    {LOG_CORE, KEYBOARD_TEST,            "KeyboardTest"},
    {LOG_CORE, KEYBOARD_ADAPTOR,         "KeyboardAdaptor"}
};

// Besides, make sure module is less than POWERMGR_MODULE_BUTT.
#define KEYBOARD_HILOGF(module, ...) (void)OHOS::HiviewDFX::HiLog::Fatal(KEYBOARD_LABEL[module], __FORMATED(__VA_ARGS__))
#define KEYBOARD_HILOGE(module, ...) (void)OHOS::HiviewDFX::HiLog::Error(KEYBOARD_LABEL[module], __FORMATED(__VA_ARGS__))
#define KEYBOARD_HILOGW(module, ...) (void)OHOS::HiviewDFX::HiLog::Warn(KEYBOARD_LABEL[module], __FORMATED(__VA_ARGS__))
#define KEYBOARD_HILOGI(module, ...) (void)OHOS::HiviewDFX::HiLog::Info(KEYBOARD_LABEL[module], __FORMATED(__VA_ARGS__))
#define KEYBOARD_HILOGD(module, ...) (void)OHOS::HiviewDFX::HiLog::Debug(KEYBOARD_LABEL[module], __FORMATED(__VA_ARGS__))
} // namespace Finance
} // namespace SwanLink

#else

#define KEYBOARD_HILOGF(...)
#define KEYBOARD_HILOGE(...)
#define KEYBOARD_HILOGW(...)
#define KEYBOARD_HILOGI(...)
#define KEYBOARD_HILOGD(...)

#endif // CONFIG_HILOG

#endif // SWANLINK_FINANCE_KEYBOARD_UTILS_NATIVE_INCLUDE_HILOG_WRAPPER_H
